home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / Libraries / ABox 1.9.5 / CPlus Files / ABUEnvDragMgr.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-10-26  |  10.0 KB  |  393 lines  |  [TEXT/MMCC]

  1. /*    
  2.     Copyright © 1991-1995 by TopSoft Inc.  All rights reserved.
  3.  
  4.     You may distribute this file under the terms of the TopSoft
  5.     Artistic License, accompanying this package.
  6.     
  7.     This file was developed by George (ty) Tempel in connection with TopSoft, Inc..
  8.     See the Modification History for more details.
  9.  
  10. Product
  11.     About Box
  12.  
  13. FILE
  14.     ABUEnvDragMgr.c
  15.  
  16. NAME
  17.     ABUEnvDragMgr.c, part of the ABox project source code,
  18.     responsible for mix-in handling the AboutBox DragMgr environment stuff.
  19.  
  20. DESCRIPTION
  21.     This file contains defines for the about box modules.
  22.     
  23. DEVELOPED BY
  24.     George (ty) Tempel                ttempel@monmouth.com
  25.     All code in this file, and its associated header file was
  26.     Created by George (ty) Tempel in connection with the TopSoft, Inc.
  27.     "FilterTop" application development, except where noted.
  28.  
  29. CARETAKER - George (ty) Tempel <ttempel@monmouth.com>
  30.      Please consult this person for any changes or suggestions to this file.
  31.  
  32. MODIFICATION HISTORY
  33.  
  34.     dd mmm yy    -    xxx    -    patchxx: description of patch
  35.     27 June 94    -    ty    -    Initial Version Created
  36.     20-july-94    -    ty    -    initial version released
  37.     28-july-94    -    ty    -    fixes to watch for Region errors during drag process
  38.     1-aug-94    -    ty    -    added code to deal with the DragSendProc
  39.     27-apr-95    -    ty    -    1.0.7--fixed detection for the drag manager, since
  40.                                 a bug was reported when running on Sys 7.1
  41.                                 French-Canadian system (!)...thanks simon!
  42.     23-may-95    -    ty    -    changes for compatibility with the CodeWarrior CW6
  43.                             release and the associated Universal Headers from Apple:
  44.                             most methods that returned references now have "Ref" at
  45.                             the end of their methods names to prevent possible collisions
  46.                             with datatypes and classes of the same name (older versions
  47.                             of the compiler didn't have a problem with this).
  48.  
  49.     25-oct-95    -    ty    -    changes for "const" usage under CW7; simplification of Boolean
  50.                             query methods
  51. */
  52.  
  53. /*===========================================================================*/
  54.  
  55. /*======= Segmentation directives ========*/
  56.  
  57. #ifdef USE_MANUAL_SEGMENTATION
  58. #pragma segment ty
  59. #endif
  60.  
  61. /*============ Header files ==============*/
  62.     
  63. #include     "ABUEnvDragMgr.h"
  64.  
  65. /*=============== Globals ================*/
  66.  
  67. /*================ CODE ==================*/
  68.  
  69.  
  70. /*=============================== ABUEnvDragMgr::ABUEnvDragMgr ================================*/
  71. ABUEnvDragMgr::ABUEnvDragMgr(void)
  72. {
  73.     mDragReference = NULL;
  74.     mItemReference = (ItemReference)1;
  75.     mDragRegion = NULL;
  76.     mDragRect.left = mDragRect.right = mDragRect.top = mDragRect.bottom = 0;
  77.     mDragUPP = NULL;
  78.     mDragMgrEvent = NULL;
  79.     mDragInitialized = false;
  80. }    // end ABUEnvDragMgr
  81.  
  82.  
  83.  
  84. /*=============================== ABUEnvDragMgr::~ABUEnvDragMgr ================================*/
  85. ABUEnvDragMgr::~ABUEnvDragMgr(void)
  86. {
  87.     this->End();
  88. }    // end ~ABUEnvDragMgr
  89.  
  90.  
  91.  
  92. /*=============================== ABUEnvDragMgr::IsPresent ================================*/
  93. Boolean    ABUEnvDragMgr::IsPresent(void)
  94. {
  95.     if (this->CheckGestalt(gestaltDragMgrAttr) == noErr)
  96.     {
  97. #if powerc || GENERATINGCFM
  98.     //    If running on a PowerPC, make sure that we not only have the
  99.     //    68K Drag Manager, but also the PowerPC shared library, too.
  100.         if ((Ptr)NewDrag != kUnresolvedSymbolAddress)
  101.             this->IndicatorRef() = ((this->GetResult() & ((1 << gestaltDragMgrPresent) | (1 << gestaltPPCDragLibPresent))) != 0);
  102. #else
  103.         this->IndicatorRef() = ((this->GetResult() & (1 << gestaltDragMgrPresent)) != 0);
  104. #endif
  105.             
  106.     } else {
  107.         this->IndicatorRef() = false;
  108.     }
  109.  
  110.     return this->IndicatorRef();
  111. }    // end IsPresent
  112.  
  113.  
  114.  
  115. /*=============================== ABUEnvDragMgr::OutlineRegion ================================*/
  116. OSErr    ABUEnvDragMgr::OutlineRegion(void)
  117. {
  118.     OSErr        error = noErr;
  119.     RgnHandle    tempRegion;
  120.     
  121.     //    begin here...
  122.     
  123.     tempRegion = ::NewRgn();
  124.     if (!tempRegion)
  125.         return memFullErr;
  126.     
  127.     //    1.0.6 ty...added check for the dragRegion having been
  128.     //                created properly
  129.     if (!this->HasDragRegion())
  130.         return memFullErr;
  131.         
  132.     ::CopyRgn (this->DragRegionRef(), tempRegion);
  133.     error = ::QDError();
  134.     if (error)
  135.         return error;
  136.         
  137.     ::InsetRgn (tempRegion, 1, 1);
  138.     error = ::QDError();
  139.     if (error)
  140.         return error;
  141.         
  142.     ::DiffRgn (this->DragRegionRef(), tempRegion, this->DragRegionRef());
  143.     error = ::QDError();
  144.     if (error)
  145.         return error;
  146.         
  147.     ::DisposeRgn(tempRegion);
  148.     error = ::QDError();
  149.     return error;
  150.         
  151. } // end OutlineRegion
  152.  
  153.  
  154.  
  155.  
  156. /*=============================== ABUEnvDragMgr::Initialize ================================*/
  157. OSErr    ABUEnvDragMgr::Initialize(void)
  158. {
  159.     OSErr                error;
  160.     
  161.     //    OVERRIDE THIS FUNCTION, but be sure to invoke this one from the
  162.     //    overriding function!
  163.     
  164.     if (!this->IsPresent())
  165.     {
  166.         return paramErr;
  167.     } else if (this->IsDragInitialized()) {
  168.         return noErr;
  169.     } // end if block
  170.     
  171.     error = ::NewDrag(&(this->DragRef()));
  172.     if (error)
  173.         return error;
  174.     
  175.     this->DragInitializedRef() = true;
  176.     this->DragRegionRef() = ::NewRgn();
  177.     if (!this->HasDragRegion())
  178.         return memFullErr;
  179.         
  180.     this->DragUPPRef() = NewDragSendDataProc (SendProc);
  181.     if (!this->HasDragUPP())
  182.         return paramErr;
  183.  
  184.  
  185.     return error;
  186.  
  187. }    // end Initialize
  188.  
  189.  
  190.  
  191.  
  192. /*=============================== ABUEnvDragMgr::Begin ================================*/
  193. OSErr    ABUEnvDragMgr::Begin(void)
  194. {
  195.     OSErr    error = paramErr;
  196.     
  197.     //    OVERRIDE THIS FUNCTION!
  198.     if (this->IsPresent() && this->IsDragInitialized() && this->HasDragMgrEvent())
  199.     {
  200.         //    set the draggable item's bounding rectangle
  201.         error = this->MakeDragRegion ();
  202.     
  203.         //    1.0.6 ty...extended the error checking the the
  204.         //                line below to avoid region problems.
  205.         //
  206.         if (!error && this->HasDragRegion() && this->HasDrag())
  207.         {
  208.             //    draw a hollow thing...
  209.             error = this->OutlineRegion ();
  210.             if (!error)
  211.                 //    1.0.7 ty...set the drag send proc just in case
  212.                 error = ::SetDragSendProc (this->DragRef(), this->DragUPPRef(), NULL);
  213.  
  214.             if (!error)
  215.                 //    now do the drag...
  216.                 error = ::TrackDrag (this->DragRef(),
  217.                                     this->DragMgrEventRef(),
  218.                                     this->DragRegionRef());
  219.         } else {
  220.             error = paramErr;
  221.         } // end if block
  222.     } // end if block
  223.     
  224.     return error;
  225.  
  226. }    // end Begin
  227.  
  228.  
  229.  
  230.  
  231.  
  232. /*=============================== ABUEnvDragMgr::End ================================*/
  233. OSErr    ABUEnvDragMgr::End(void)
  234. {
  235.     //    OVERRIDE THIS FUNCTION!
  236.     
  237.     if (this->HasDragUPP())
  238.     {
  239.         DisposeRoutineDescriptor (this->DragUPPRef());
  240.         this->DragUPPRef() = NULL;
  241.     } // end if block
  242.     
  243.     if (this->HasDrag() && this->IsPresent())
  244.     {
  245.         ::DisposeDrag(this->DragRef());
  246.         this->DragRef() = NULL;
  247.     } // end if block
  248.         
  249.     if (this->HasDragRegion())
  250.     {
  251.         ::DisposeRgn(this->DragRegionRef());
  252.         this->DragRegionRef() = NULL;
  253.     } //
  254.     
  255.     this->DragInitializedRef() = false;
  256.     return noErr;
  257.  
  258. }    // end End
  259.  
  260.  
  261.  
  262.  
  263. /*=============================== ABUEnvDragMgr::GetDropLocationDirectory ================================*/
  264. OSErr    ABUEnvDragMgr::GetDropLocationDirectory( AEDesc *dropLocation,
  265.                                     long *directoryID,
  266.                                     short *volumeID)
  267. {
  268.     OSErr            error;
  269.     AEDesc            targetDescriptor;    //    'fss ' descriptor for target directory
  270.     FSSpec            targetLocation;        //    FSSpec for target directory
  271.     CInfoPBRec        getTargetInfo;        //    paramBlock to get targetDirID
  272.     
  273.     //    Coerce the 'alis' descriptor to a 'fss ' descriptor
  274.     error = ::AECoerceDesc(dropLocation, typeFSS, &targetDescriptor);
  275.     if (error)
  276.         return error; 
  277.     
  278.     //    Extract the FSSpec from targetDescriptor
  279.     ::BlockMove((Ptr)(*targetDescriptor.dataHandle), (Ptr)&targetLocation, sizeof(FSSpec));
  280.     
  281.     error = ::AEDisposeDesc(&targetDescriptor);
  282.     if (error)
  283.         return error;
  284.     
  285.     //    Use PBGetCatInfo to get the directoryID of the target directory
  286.     //    from the FSSpec
  287.     
  288.     getTargetInfo.dirInfo.ioNamePtr = targetLocation.name;
  289.     getTargetInfo.dirInfo.ioVRefNum = targetLocation.vRefNum;
  290.     getTargetInfo.dirInfo.ioFDirIndex = 0;
  291.     getTargetInfo.dirInfo.ioDrDirID = targetLocation.parID;
  292.     
  293.     error = ::PBGetCatInfoSync(&getTargetInfo);
  294.     if (error)
  295.         return error;
  296.     
  297.     //    return directory ID and volume reference number
  298.     
  299.     *directoryID = getTargetInfo.dirInfo.ioDrDirID;
  300.     *volumeID = targetLocation.vRefNum;
  301.     
  302.     return error;
  303. }    // end GetDropLocationDirectory
  304.                                                     
  305.  
  306.  
  307.  
  308. /*=============================== ABUEnvDragMgr::MakeDragRegion ================================*/
  309. OSErr    ABUEnvDragMgr::MakeDragRegion (void)
  310. {
  311.     OSErr            error = noErr;
  312.     RgnHandle        tempRegion;
  313.     Point            offset;
  314.     
  315.     //    begin here...
  316.     
  317.     tempRegion = ::NewRgn();
  318.     if (!(this->HasDragRegion() && tempRegion))
  319.         return memFullErr;
  320.     
  321.     offset.h = offset.v = 0;
  322.     ::LocalToGlobal (&offset);
  323.     ::OffsetRect (&(this->DragRectRef()), offset.h, offset.v);
  324.     ::RectRgn (tempRegion, &(this->DragRectRef()));
  325.     error = ::QDError();
  326.     if (error)
  327.         return error;
  328.         
  329.     ::UnionRgn (tempRegion, this->DragRegionRef(), this->DragRegionRef());
  330.     error = ::QDError();
  331.     if (error)
  332.         return error;
  333.         
  334.     ::DisposeRgn(tempRegion);
  335.     error = ::SetDragItemBounds (this->DragRef(),
  336.                                 this->ItemRef(),
  337.                                 &(this->DragRectRef()));
  338.     ::DisposeRgn (tempRegion);
  339.     return error;
  340. } // end MakeDragRegionRef()
  341.  
  342.  
  343.  
  344.  
  345. /*=============================== ABUEnvDragMgr::SendProc ================================*/
  346. //
  347. //    The SendProc() for the class, this static method shown below, is the high-level
  348. //    interface between us, the class, and the DragMgr. Additionally, it is used to invoke
  349. //    the LocalSendProc() of sub-class instances. In this manner we can provide a class-level
  350. //    interface for the DragMgr (static functions) without sacrificing the nice subclassing
  351. //    and virtual function characteristics of C++. The dragSendRefCon is a pointer to the
  352. //    object instance. Neat, huh?
  353. //
  354. pascal    OSErr    ABUEnvDragMgr::SendProc(FlavorType theType,
  355.                                         void *dragSendRefCon,
  356.                                         ItemReference theItemRef,
  357.                                         DragReference theDragRef)
  358. {
  359.     OSErr    error = noErr;
  360.     
  361.  
  362.     if (dragSendRefCon)
  363.     {
  364.         error = ((ABUEnvDragMgr *)(dragSendRefCon))->LocalSendProc (theType,
  365.                                                 dragSendRefCon,
  366.                                                 theItemRef,
  367.                                                 theDragRef);
  368.     } // end if block
  369.     
  370.     return error;
  371. } // end SendProc()
  372.  
  373.  
  374.  
  375.  
  376.  
  377. /*=============================== ABUEnvDragMgr::LocalSendProc ================================*/
  378. //
  379. OSErr    ABUEnvDragMgr::LocalSendProc(FlavorType theType,
  380.                                     void* dragSendRefCon,
  381.                                     ItemReference theItemRef,
  382.                                     DragReference theDragRef)
  383. {
  384. #pragma unused (theType, dragSendRefCon, theItemRef, theDragRef)
  385.  
  386.     return noErr;
  387.     
  388. } // end LocalSendProc()
  389.  
  390.  
  391.  
  392. //    end of file.
  393.